import { get, post, del } from '@/axios'
const moduleUrl = '/umsAdmin'
const url = {
	page: moduleUrl + '/page',
	add: moduleUrl + '/add',
	check: moduleUrl + '/check',
	getById: moduleUrl + '/getInfo',
	update: moduleUrl + '/update',
	del: moduleUrl + '/remove',
	list: moduleUrl + '/list'
}
const getList = () => {
	return new Promise(resolve => {
		get(url.list, { }, content => {
			resolve(content)
		})
	}) 
}
const getTableData = (params) => {
	return new Promise(resolve => {
		get(url.page, params, content => {
			resolve(content)
		})
	}) 
}
const getById = (id) => {
	return new Promise(resolve => {
		get(url.getById + `/${id}`, { id }, content => {
			resolve(content)
		})
	})
}
const addOrUpdate = (id, params, callback ,formObj = null) => {
	post(id ? url.update : url.add, params, content => {
		callback(content)
	} , formObj)
	
}
const remove = (id, callback) => {
	del(url.del, { id }, content => {
		callback(content)
	})
}
const check = (field, value, callback, id = null) => {
	return new Promise((resolve, reject) => {
		get(url.check, { field, value, id }, content => {
			if(content) {
				resolve()
			} else {
				reject(new Error())
			}
		})
	})
}
export default {
	getTableData,
	addOrUpdate,
	remove,
	getById,
	check,
	getList
}